<!doctype html>
<html lang="en">
<head>
<title>设备备品配件领用</title>
	<meta name="keywords" content="keyword1,keyword2,keyword3">
	<meta name="description" content="载具清洗">
	<meta name="content-type" content="text/html; charset=UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" type="text/css" href="../../script/js/layui/css/layui.css" media="all">
	<script type="text/javascript" src="../../script/js/layui/layui.js"></script>
	<script type="text/javascript" src="../../mes/js/vue.min.js"></script>
	<script type="text/javascript" src="../../script/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../mes/js/vue-resource.min.js"></script>
</head>
<body id="production" align="center">
<form class="layui-form layui-form-pane">
	 <fieldset class="layui-elem-field layui-field-title">
		<legend><font color="white">设备备品配件领用</font></legend>
		<div class="layui-form-item">
			<div class="layui-inline">
					<label class="layui-form-label" style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp;物料编码</label>
					<div class="layui-input-inline">
						<input type="text" class="layui-input" id="toolId" v-model="record.CODE" @keyDown="getToolInfoByCode" placeholder="请扫描物料条码">
					</div>
			</div>
		</div>
		<div class="layui-form-item">	
			<div class="layui-inline">
					<label  class="layui-form-label"  style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 规格/型号</label>
					<div class="layui-input-inline">
				    	<input type="text" class="layui-input" id="Specifications" required="required"></textarea>
				    </div>
			</div>
		</div >
		
		<div class="layui-form-item">	
			<div class="layui-inline">
					<label  class="layui-form-label"  style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 物料名称</label>
					<div class="layui-input-inline">
				    	<input type="text" class="layui-input" id="Materialname" required="required"></textarea>
				    </div>
			</div>
		</div >
		
		
		
	 </fieldset>
	 

<div id="confirmReceiveDiv" style="display: none;">
<form class="layui-form layui-form-pane" id="editForm">
 <fieldset class="layui-elem-field layui-field-title">
			<div class="layui-form-item" align="center">
				<div class="layui-inline" style="color:gray;">
					<label  class="layui-form-label"  style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 物料编码</label>
					<div class="layui-input-inline">
				    	<input type="text" class="layui-input" id="reMakeNum" required="required" readonly="readonly"></textarea>
				    </div>
				</div>
			
				<div class="layui-inline" style="color:gray;" >
					<label  class="layui-form-label"  style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 物料名称</label>
					<div class="layui-input-inline">
				    	<input type="text" class="layui-input" id="ZAIJUCODE" required="required" readonly="readonly" ></textarea>
				    </div>
				</div>
				
				<div class="layui-inline" style="color:gray;">
					<label  class="layui-form-label"  style="width:230px;background-color:red;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 库存数量</label>
					<div class="layui-input-inline">
				    	<input type="text" class="layui-input" id="ZAIJUNAME" required="required" readonly="readonly"></textarea>
				    </div>
				</div>
				
				<div class="layui-inline" style="color:gray;">
					<label  class="layui-form-label"  style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 安全库存数量</label>
					<div class="layui-input-inline">
				    	<input type="text" class="layui-input" id="ANQUANKUCUNNUMBERS" required="required" readonly="readonly"></textarea>
				    </div>
				</div>
				
				<div class="layui-inline" style="color:gray;">
					<label  class="layui-form-label"  style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 单位</label>
					<div class="layui-input-inline">
				    	<input type="text" class="layui-input" id="COMPANY" required="required" readonly="readonly"></textarea>
				    </div>
				</div>
				
				<div class="layui-inline">
					<label class="layui-form-label" style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 车间</label>
					<div class="layui-input-inline">
						<select name="modules" lay-verify="required" lay-search="" lay-filter="orgchejian" id="setOrg">
					        	<option value="">直接选择或搜索选择</option>
								<option v-for="allorg in allorgs" value="{{allorg.ORGID}}" id ="YINGCANGIDS">{{allorg.NAME}}</option>
			        	</select>
					</div>
				</div>
				
				<div class="layui-inline">
					<label class="layui-form-label" style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 工序</label>
					<div class="layui-input-inline">
						    <select name="modules" lay-verify="required" lay-search=""  lay-filter="gongxuIds" id = "processids">
								<option value="">直接选择或搜索选择</option>
								<option v-for="processname in processnames" value="{{processname.PROCESSID}}" >{{processname.NAME}}</option>
							</select>
					</div>
				</div>
				
				<div class="layui-inline">
					<label class="layui-form-label" style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 设备编码--名称</label>
					<div class="layui-input-inline">
						<select name="modules" lay-verify="required" lay-search="" lay-filter="SheBEIID" id = "equipmentids">
			        	<option value="">直接选择或搜索选择</option>
			          	<option v-for="sel in sels" value="{{sel.SBID}}" >{{sel.CODE}}——{{sel.NAME}}</option>
			        </select>
					</div>
				</div>
				
				<div class="layui-inline">
					<label class="layui-form-label" style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 供应商</label>
					<div class="layui-input-inline">
						<select name="modules" lay-verify="required" lay-search="" lay-filter="SUPPLIERSID" id = "SUPPLIERSIDS">
			        	<option value="">直接选择或搜索选择</option>
			          	<option v-for="GONGYINGSHANG in Suppliers" value="{{GONGYINGSHANG.GYSID}}" >{{GONGYINGSHANG.GYSNAME}}</option>
			        </select>
					</div>
				</div>
				
				
				<div class="layui-inline">
					<label class="layui-form-label" style="width:230px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 储位</label>
					<div class="layui-input-inline">
						<select name="modules" lay-verify="required" lay-search="" lay-filter="VENDORID" id = "KUNCUNIDS">
			        	<option value="">直接选择或搜索选择</option>
			          	<option v-for="WLKW in Storages" value="{{WLKW.KWID}}" >{{WLKW.BARCODE}}</option>
			        </select>
					</div>
				</div>
				
				
				
				<div class="layui-inline" style="color:gray;">
					<label  class="layui-form-label"  style="width:230px;background-color:yellow;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp; 指定储位库存数量</label>
					<div class="layui-input-inline">
							<input type="text" id="types6" class="layui-input" value="" v-model="vendornumbers" disabled="" style="color:gray;">
					</div>
				</div>
				
				<div class="layui-inline">
					<label class="layui-form-label" style="width:230px;background-color:yellow;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp;领用数量</label>
					<div class="layui-input-inline">
						<input type="text" class="layui-input" id="CollarNumbers" required="required"></textarea>
					</div>
				</div>
				
				<div class="layui-form-item layui-form-text">
					 <label class="layui-form-label" style="width:860px;"><span class="layui-badge-dot layui-bg-orange"></span>&nbsp; &nbsp;领用说明</label>
					 <div class="layui-input-block">
					 <textarea placeholder="请输入内容" class="layui-textarea" id="workflowrank" style="width:860px; height:200px; "></textarea>
					 
					 </div>
					    
  				</div>
			</div>
</fieldset>
	
</form>
</div>


	<div class="layui-form-item">
		<button type="button"  class="layui-btn" @click="saveToolCleanRecord">搜索</button>
		&nbsp;&nbsp;&nbsp;&nbsp;
		<button type="button" class="layui-btn" @click="reset">重置</button>
	</div>
	<script type="text/html" id="remakeReceiveAction">
		<a class="layui-btn layui-btn-xs" lay-event="yes">领用</a>
	</script>
	<table class="layui-hide" id="efficiencyTable" lay-filter="remakeReceiveFilter"></table>
	
</form>
<script type="text/javascript">
var lastresult = true;
var zjname = "";
var vm = new Vue({
	el : "#production",
	data : {
		record:{},
		allorgs:[],
		processnames:[],
		sels:[],
		Storages:[],
		Suppliers:[],
		vendornumbers:{}
	},
	init:function(){
		var _self = this;
  		layui.use(['layer'], function(){
  			layer = layui.layer;
        });
      	 this.$nextTick(function() {
				this.$http.post("../../Spareparts/Inquireallresult",{},{emulateJSON: true}).then(function(res){
					if(res.ok){
						_self.tableData = res.body.Stocks;
						_self.allorgs = res.body.adorgname;
						_self.processnames = res.body.processname;
						
						_self.$options.methods.renderTable(_self,res.body.Stocks);
						
						
					}
					layui.use(['form'], function(){
						var form = layui.form;
						
						form.on('select(gongxuIds)', function(data){
							 _self.gxname = data.value;
							 var types = $('#setOrg option:selected').val();        //车间
					         $.ajax({
							    url: "../../Spareparts/Equipmentcode",
							    type: 'POST',
							    async: false,
							    data: {
							           ORGNAME:types,
							           GXNAME:_self.gxname
								},
							    dataType: 'json',
								success: function(data) {
								   if(data.result){										   	   
									   _self.sels = data.Plans;
								   	   									   	   
								   	   window.setTimeout(function() {
								   	   		form.render("select");
								   	   }, 100);
								   	   
								   }else{
								       layer.msg("处理失败");
								   }
								}
							});
					   	});
						
						form.on('select(VENDORID)', function(data){
							 _self.kwname = data.value;
							    
						  	var wlcode = document.getElementById("reMakeNum").value;       //获取物料编码的值;
						  	//var gongyingshangIds = $('#SUPPLIERSIDS option:selected').val();        //获取供应商的值;
					         $.ajax({
							    url: "../../Spareparts/EquipmentVendor",
							    type: 'POST',
							    async: false,
							    data: {
							           KWNAME: _self.kwname,
							           //GYSIDS : gongyingshangIds,
							           WLCODE : wlcode
								},
							    dataType: 'json',
								success: function(data) {
								   if(data.result){										   	   
									   _self.vendornumbers = data.vendors[0].QTY;
								   	   				
								   }else{
								       layer.msg("处理失败");
								   }
								}
							});
					   	});
						
						/* form.on('select(SUPPLIERSID)', function(data){
							 _self.gysname = data.value;
							    
						  	var wlcode = document.getElementById("reMakeNum").value;       //获取物料编码的值;
						  	var chuweiIDs = $('#KUNCUNIDS option:selected').val();        //获取储位的值;
					         $.ajax({
							    url: "../../Spareparts/EquipmentVendor",
							    type: 'POST',
							    async: false,
							    data: {
							           KWNAME: chuweiIDs,
							           GYSIDS : _self.gysname,
							           WLCODE : wlcode
								},
							    dataType: 'json',
								success: function(data) {
								   if(data.result){										   	   
									   _self.vendornumbers = data.vendors[0].QTY;
								   	   				
								   }else{
								       layer.msg("处理失败");
								   }
								}
							});
					   	}); */
						
					});
				});
		 }); 
		 
        $("#toolId").select();
	},
	methods: {
		saveToolCleanRecord: function(data){
			var _self = this;
			
			var Epcode = document.getElementById("toolId").value;   //物料编码
			var wlnames = document.getElementById("Materialname").value;  //物料名称
			var models = document.getElementById("Specifications").value;	//规格型号
			
			if(Epcode == "" && wlnames ==  "" && models == "" ){
				layer.msg("请至少输入一个筛选条件！");
			}else{		
				var data ={
					Epcode : Epcode,
					wlnames : wlnames,
					models : models
				};
				
            	 this.$nextTick(function() {
 					this.$http.post("../../Spareparts/Submission",data,{emulateJSON: true}).then(function(res){
 						if(res.ok){ 		
 							_self.condition = res.body.conditions;				
 							
 							_self.$options.methods.renderTable(_self,res.body.conditions);
 							
 						}else{
 						   layer.msg("查询失败"); 	
 						}			
 					  	
 			 		});
 				}); 
			}	
		},
        getToolInfoByCode: function(event){
            var _self = this;
           
            if (event.keyCode != 13 || !(_self.record.CODE && _self.record.CODE.length > 0)) {
                return;
            }
            
            _self.$nextTick(function() {
                _self.$http.post("../../Spareparts/getSparepartscounts",{toolCode:_self.record.CODE},{emulateJSON: true}).then(function(res){
                	if(res.ok){
	                	_self.materiel = res.body.materiels;
	                    if(_self.materiel.length == 0){
	                        _self.vueAlert("此物料不存在！");
	                        return;
						}
	                    _self.record = res.body.materiels;
	                    
	                    if(lastresult){
	                    	 _self.$options.methods.openConfirmReceiveWindow(res.body.materiels[0],_self);
	                    }
	                   
	                    $("#toolId")[0].select();
               		 }
            	});
            });
            
           
		}
		,reset: function(data){
			window.location.reload();
		}
        ,vueAlert: function(msg){
            layui.use(['form'], function(){
                var layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        },
        renderTable: function(_self,data){
        	
			layui.use(['form','table','laydate'], function(){
				  var table = layui.table;
				  var form = layui.form;
				  
				  table.render({
				    elem: '#efficiencyTable'
				    ,height: 'full-60'
				    ,cols: [[ //标题栏
				       {fixed:'left',type:'numbers',title:'序号'}
				      ,{fixed:'left',field: 'WLCODE', title: '物料编码',width:140}
				      ,{field: 'WLNAME', title: '物料名称',minWidth:140,align:'center' }
				      ,{field: 'MODEL', title: '型号/规格',minWidth:160,align:'center'}
				      ,{field: 'ANNUMBERS', title: '安全库存数量', minWidth:60,align:'center'}
				      ,{field: 'COMPANY', title: '单位', minWidth: 40,align:'center'}
				      ,{field: 'GXNAME', title: '工序名称', minWidth: 100,align:'center'}
				      ,{field: 'CYCLE', title: '备件类型/周期', minWidth: 120,align:'center'}
				      ,{fixed: 'right',title:'操作', align:'center', toolbar: '#remakeReceiveAction'}
				    ]]
				    ,data:data
				    ,page: true //是否显示分页
				    ,limits: [10, 20, 50]
				    ,limit: 15 //每页默认显示的数量
				  });
				  //监听工具条
					table.on('tool(remakeReceiveFilter)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
						 
						var row = obj.data //获得当前行数据
							,layEvent = obj.event; //获得 lay-event 对应的值
						if(layEvent == 'yes'){
							_self.openConfirmReceiveWindow(row,_self);
							 
						}else if(layEvent == 'no'){
							_self.refuse(row,_self,obj);
						}
					});
				  
				});
		}
		,openConfirmReceiveWindow: function(data,_self){
			var indexReceiveWindow = layer.open({
				type : 1,
				title : '设备备品配件领料单',
				id : 'sssss',
				shadeClose : true,
				skin: 'layui-layer-lan',
				shade : 0.8,
				area : [ '60%', '65%' ],
				content : $('#confirmReceiveDiv')
				,btn: ['确认', '取消']
				,btnAlign: 'c'
			  	,yes: function(index, layero){
			  		var Collars = document.getElementById("CollarNumbers").value;  //获取领用数量的值;
			  		var ZAIJUNAMES = document.getElementById("ZAIJUNAME").value;  //获取库存数量的值;
			  		var Stocknumbers = document.getElementById("types6").value;  //获取物料指定在库存数量的值;
			  		var beizhu = document.getElementById("workflowrank").value;  //获取领用说明的值;
			  		var chuweiids = $('#KUNCUNIDS option:selected').val();        //获取储位的值;
			  		var gongxuname = $('#processids option:selected').val();        //获取工序的值;
			  		var gongyingshangIds = $('#SUPPLIERSIDS option:selected').val();        //获取供应商的值;
			  		var orgnames = $('#setOrg option:selected').val();        //车间
			  		var shebeiname = "";
			  		if(orgnames == "" || gongxuname == "" ){
			  			layer.msg("请选择物料所用车间和工序！！");
			  			return;
			  		}else{
			  		   shebeiname = $('#equipmentids option:selected').val();  //获取设备的值;
			  		}
			  		
			  		
			  		
			  		if(orgnames == ""){
			  			layer.msg("请先选择物料所用车间！！");
			  			return;
			  		}else{
			  			if(gongxuname == ""){
				  			layer.msg("请先选择物料所用工序！！");
				  			return;
				  		}else{
				  			if( shebeiname== ""){
					  			layer.msg("请先选择物料所用设备！！");
					  			return;
					  		}else{
					  			if(chuweiids == ""){
						  			layer.msg("请先选择物料所用储位！！");
						  			return;
						  		}else{
						  			if(Collars == ""){
						  				layer.msg("请先输入领用数量！！");
						  			}else{
						  				if(!(/^[1-9]\d*$/.test(Collars))){
						  					layer.msg("领用数量请填写正整数！！");
						  				}else{
						  					//if(gongyingshangIds == ""){
						  					//	layer.msg("请选择供应商！！");
						  					//}else{
						  					    //判读领用数量是否超过库存数量
										  		if(parseInt(Collars)  >  parseInt(Stocknumbers)){
										  			layer.msg("该储位上物料库存数量不足！！");
										  			return;
										  		}else{
								                    layer.confirm("确定领用:"+data.WLNAME+"物料？", {icon: 5, title:'提示'}, function(index){
								                        _self.$nextTick(function() {
								                            _self.$http.post("../../Spareparts/SparepartsCleanReport",{
								                            	MATERIEL : data.WLID,
								                            	WULNAMES : data.WLNAME,
								                            	WULCODES : data.WLCODE,
																LOCATOR : data.KWID,
																COMPANYS : data.COMPANY,
																GONGXU : gongxuname,
																SHEBEI : shebeiname,
																BEIZHUS : beizhu,
																COLLAR : Collars,
																KUSHULIANG : _self.number,
																ANNUMBER : data.ANNUMBERS,
																ORGIDS : orgnames,
																CHUWEIS : chuweiids,
																GYSNAMES : gongyingshangIds,
                                                                orgName:$('#setOrg option:selected').text(),
																processName:$('#processids option:selected').text(),
                                                                facCodeAndName:$('#equipmentids option:selected').text()
															},{emulateJSON: true}).then(function(resData){
																 
																layer.msg("领用申请已提交，等待确认！");
																window.setTimeout(function() {
																	window.location.reload();
															        }, 1000);
								                            });
								                        });
								                        layer.close(index);
								                        layer.close(indexReceiveWindow);
								                    });
										  		}	
						  					//}
						  				
						  				}
						  			}
						  		}
					  		}
				  		}
			  		}
			  		
			  		
			  		
			  		
			  	}
				,btn2: function(index, layero){
			    	//按钮【按钮二】的回调
			    	//return false 开启该代码可禁止点击该按钮关闭
			    	_self.clearReceiveForm();
					window.location.reload();
			  	}
			  	,cancel: function(){ 
			    	//右上角关闭回调
			    	//return false 开启该代码可禁止点击该按钮关闭
			    	//_self.clearReceiveForm();
					window.location.reload();
			  	}
			  	,success: function(layero, index){
			  		
			  		$.ajax({
					    url: "../../Spareparts/SumMaterielsresult",
					    type: 'POST',
					    async: false,
					    data: {
					    	toolCode: data.WLCODE
						},
					    dataType: 'json',
						success: function(data) {
						   if(data.result){										   	   
							   _self.number = data.sumnumbers[0].QTY;
								_self.Suppliers = data.Supplier;
								_self.Storages = data.Storage;
								

						    	$("#ZAIJUNAME").val(_self.number);
						   	   
						   }else{
						       layer.msg("处理失败");
						   }
						}
					});
			  		
			    	$("#reMakeNum").val(data.WLCODE);
			    	$("#ZAIJUCODE").val(data.WLNAME);
			    	$("#COMPANY").val(data.COMPANY);
			    	$("#ANQUANKUCUNNUMBERS").val(data.ANNUMBERS);
			    	
			    	
			  	}
			});
		}
		,clearReceiveForm: function(){
			$("#reMakeNum").val('');
			$("#confirmReceiveNum").val('');
		}
        
	}
});

$("#toolId")[0].select();
</script>
</body>
</html>
